package com.interest.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class RegexUtils {
	private RegexUtils() {

	}
	/**
	 * 对字符串进行正则匹配
	 * @param regex 正则表达�?
	 * @param str	�?要匹配的字符�?
	 * @return
	 */
	public static boolean regexMatch(String regex,String str){
		boolean flag = false;
		if(!"".equals(regex)&&!"".equals(str)){
			Pattern p = Pattern.compile(regex);
			Matcher match = p.matcher(str);
			flag = match.matches();
		}
		return flag;
	}
	public static String getMatchedString(String regex, String str, int flag) {
		Pattern p = Pattern.compile(regex);
		Matcher match = p.matcher(str);

		String result = "";
		if (match.find()) {
			result = match.group(flag);
		}

		return result;
	}

	public static boolean isMatchedString(String regex, String str) {
		Pattern p = Pattern.compile(regex);
		Matcher match = p.matcher(str);
		return match.matches();
	}

	/**
	 * 判断是否是手机号�?
	 * 
	 * @param cellPhoneNum
	 * @return
	 */
	public static boolean isCellPhoneNum(String cellPhoneNum) {
		return RegexUtils.isMatchedString("^[1][3578][0-9]{9}$", cellPhoneNum);
	}

//	/**
//	 * 返回指定字符串是否为�?个ip
//	 * 
//	 * @param ip
//	 * @return
//	 */
//	public static boolean isIP(String ip) {
//		if (StringUtils.isNotBlank(ip)) {
//			String ipRegex = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
//					+ "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\." + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
//					+ "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";
//			return RegexUtils.isMatchedString(ipRegex, ip);
//		}
//		return false;
//	}
}
